package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CarPartFastener;
import com.ruoyi.system.service.ICarPartFastenerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@Controller
@RequestMapping("/system/fastener")
public class CarPartFastenerController extends BaseController
{
    private String prefix = "system/fastener";

    @Autowired
    private ICarPartFastenerService carPartFastenerService;

    @RequiresPermissions("system:fastener:view")
    @GetMapping("{carId}/{carInfoId}")
    public String fastener(@PathVariable Long carId, @PathVariable Long carInfoId,ModelMap mmap)
    {
        CarPartFastener carPartFastener = new CarPartFastener();
        carPartFastener.setCardId(carId);
        carPartFastener.setCardInfoId(carInfoId);
        mmap.put("fasteners", carPartFastenerService.selectCarPartFastenerList(carPartFastener));
        return prefix + "/fastener";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:fastener:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarPartFastener carPartFastener)
    {
        startPage();
        List<CarPartFastener> list = carPartFastenerService.selectCarPartFastenerList(carPartFastener);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:fastener:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarPartFastener carPartFastener)
    {
        List<CarPartFastener> list = carPartFastenerService.selectCarPartFastenerList(carPartFastener);
        ExcelUtil<CarPartFastener> util = new ExcelUtil<CarPartFastener>(CarPartFastener.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:fastener:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarPartFastener carPartFastener)
    {
        AjaxResult ajaxResult = toAjax(carPartFastenerService.insertCarPartFastener(carPartFastener));
        ajaxResult.setData(carPartFastener.getId());
        return ajaxResult;
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:fastener:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CarPartFastener carPartFastener = carPartFastenerService.selectCarPartFastenerById(id);
        mmap.put("carPartFastener", carPartFastener);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:fastener:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarPartFastener carPartFastener)
    {
        return toAjax(carPartFastenerService.updateCarPartFastener(carPartFastener));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:fastener:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @GetMapping( "/remove/{id}")
    @ResponseBody
    public AjaxResult remove( @PathVariable String id)
    {
        return toAjax(carPartFastenerService.deleteCarPartFastenerByIds(id));
    }
}
